package com.ksd.pug.controller.adminlog;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ksd.pug.commons.anno.PugPermissionIngore;
import com.ksd.pug.commons.enums.ResultStatusEnumA;
import com.ksd.pug.commons.ex.PugValidationException;
import com.ksd.pug.commons.utils.fn.asserts.Vsserts;
import com.ksd.pug.config.anno.LoginCheck;
import com.ksd.pug.controller.BaseController;
import com.ksd.pug.pojo.AdminLogs;
import com.ksd.pug.service.adminlog.IAdminLogsService;
import com.ksd.pug.vo.AdminLogsVo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author: hcl
 * @date: 2022/1/24 15:03
 * @Description:
 */
@RestController
@RequiredArgsConstructor
@Slf4j
@LoginCheck
@PugPermissionIngore
public class AdminLogsController extends BaseController {
    private final IAdminLogsService adminlogsService;


    /**
     * 查看方法的耗时和次数
     *
     * @return
     */
    @PostMapping("/adminlogs/state/method/{timer}")
    public List<Map<String, Object>> selectMethodTime(@PathVariable("timer") Long timer) {
        return adminlogsService.selectMethodTime(timer);
    }

    /**
     * 统计浏览器占比
     *
     * @return
     */
    @PostMapping("/adminlogs/state/broswer")
    public List<Map<String, Object>> stateLogsBrowerversion() {
        return adminlogsService.stateLogsBrowerversion();
    }

    /**
     * 统计操作系统占比
     *
     * @return
     */
    @PostMapping("/adminlogs/state/os")
    public List<Map<String, Object>> stateLogsOSversion() {
        return adminlogsService.stateLogsOSversion();
    }

    /**
     * 查询后台日志列表信息
     *
     * 创建时间：2022-04-18 21:24:11
     */
    @GetMapping("/adminlogs/load")
    public List<AdminLogs> findAdminLogsList() {
        return adminlogsService.findAdminLogsList();
    }

    /**
     * 查询后台日志列表信息并分页
     *
     * 创建时间：2022-04-18 21:24:11
     */
    @PostMapping("/adminlogs/list")
    public IPage<AdminLogs> findAdminLogss(@RequestBody AdminLogsVo adminlogsVo) {
        return adminlogsService.findAdminLogsPage(adminlogsVo);
    }


    /**
     * 根据后台日志id查询明细信息
     *
     * 创建时间：2022-04-18 21:24:11
     */
    @GetMapping("/adminlogs/get/{id}")
    public AdminLogs getAdminLogsById(@PathVariable("id") String id) {
        if (Vsserts.isEmpty(id)) {
            throw new PugValidationException(ResultStatusEnumA.ID_NOT_EMPTY);
        }
        return adminlogsService.getAdminLogsById(new Long(id));
    }


    /**
     * 保存和修改后台日志
     *
     * 创建时间：2022-04-18 21:24:11
     */
    @PostMapping("/adminlogs/saveupdate")
    public AdminLogs saveupdateAdminLogs(@RequestBody AdminLogs adminlogs) {
        return adminlogsService.saveupdateAdminLogs(adminlogs);
    }


    /**
     * 根据后台日志id删除后台日志
     *
     * 创建时间：2022-04-18 21:24:11
     */
    @PostMapping("/adminlogs/delete/{id}")
    public int deleteAdminLogsById(@PathVariable("id") String id) {
        if (Vsserts.isEmpty(id)) {
            throw new PugValidationException(ResultStatusEnumA.ID_NOT_EMPTY);
        }
        return adminlogsService.deleteAdminLogsById(new Long(id));
    }


    /**
     * 根据后台日志ids批量删除后台日志
     *
     * 创建时间：2022-04-18 21:24:11
     */
    @PostMapping("/adminlogs/delBatch")
    public boolean delAdminLogs(@RequestBody AdminLogsVo adminlogsVo) {
        log.info("你要批量删除的IDS是:{}", adminlogsVo.getBatchIds());
        if (Vsserts.isEmpty(adminlogsVo.getBatchIds())) {
            throw new PugValidationException(ResultStatusEnumA.ID_NOT_EMPTY);
        }
        return adminlogsService.delBatchAdminLogs(adminlogsVo.getBatchIds());
    }
}
